
# -*- coding: UTF-8 -*-
import re


def parse_url(url):
    if (not "://" in url):
        url = f"lj://{url}"

    pattern = r'^(?P<scheme>[\w]+)://(?P<host>[\w.-]+):?(?P<port>\d+)?/(?P<path>[\w/]+)?\??(?P<query>[\w=&]+)?$'
    match = re.match(pattern, url)

    if match:
        groups = match.groupdict()
        return groups
    else:
        return None


def remvoe_protocol(url):
    if "http://" in url:
        return url[7:]
    if "https://" in url:
        return url[8:]

    return url
